/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiMinGWHacks.h
	Hacks so MinGW can compile this correctly!

******************************************************************************/

#ifndef MaxsiMinGWHacks_H
#define MaxsiMinGWHacks_H

#ifdef __GNUC__

//=============================================================================
//	Which hacks do we need to enable to compile under MinGW?
//=============================================================================
#ifdef __MINGW_H
#define Hack_BindIoCompletionCallback
#endif

//=============================================================================
//	Hack to make the BindIoCompletionCallback function link under MinGW.
//=============================================================================
#ifdef Hack_BindIoCompletionCallback
	typedef
	BOOL
	(WINAPI *LPBindIoCompletionCallback)(
		HANDLE FileHandle,
		LPOVERLAPPED_COMPLETION_ROUTINE Function,
		ULONG Flags
		);

	LINK BOOL BindIoCompletionCallback(HANDLE FileHandle, LPOVERLAPPED_COMPLETION_ROUTINE Function, ULONG Flags);
#endif

//=============================================================================
//	Various things that should have been defined in the headers shipped along
//	MinGW but isn't for some reason.
//=============================================================================
#ifndef PBS_MARQUEE
#define PBS_MARQUEE		0x08
#endif

#ifdef max
#undef max
#endif
#define max(a,b)            (((a) > (b)) ? (a) : (b))

#ifdef min
#undef min
#endif
#define min(a,b)            (((a) < (b)) ? (a) : (b))

#ifndef SIZE_MAX
#ifdef _WIN64 
#define SIZE_MAX ULONG_LONG_MAX
#else
#define SIZE_MAX ULONG_MAX
#endif
#endif

#ifndef PBM_SETMARQUEE
#define PBM_SETMARQUEE          (WM_USER+10)
#endif

#ifndef PBST_NORMAL
#define PBST_NORMAL             0x0001
#endif

#ifndef PBST_ERROR
#define PBST_ERROR              0x0002
#endif

#ifndef PBST_PAUSED
#define PBST_PAUSED             0x0003
#endif

#ifndef PBM_SETMARQUEE
#define PBM_SETMARQUEE          (WM_USER+10)
#endif

#ifndef PBM_SETSTATE
#define PBM_SETSTATE            (WM_USER+16) // wParam = PBST_[State] (NORMAL, ERROR, PAUSED)
#endif

#ifdef __MINGW_H
	#ifdef __MSVCRT_VERSION__
	#undef __MSVCRT_VERSION__
	#endif
	#define __MSVCRT_VERSION__ 0x0601
#endif

//=============================================================================
//	Some defines of VS specific stuff we use here
//=============================================================================
//#define __forceinline //inline
#define _CVTBUFSIZE (309+40) // Number of digits in maximum double precision value + slop
#define __debugbreak() // We haven't gotten debugging working here yet, so just ignore all this
#define __noop()

//=============================================================================
//	Ensure __func__ is what we need it to be.
//=============================================================================
#if __STDC_VERSION__ < 199901L
	#if __GNUC__ >= 2
		#define __func__ __FUNCTION__
	#else
		#define __func__ "<unknown>"
	#endif
#endif

#define ME_UNDEFINED_BEHAVIORMESTRC(Message)

#ifndef Maxsi_Support_MinGW
#define _stricmp strcasecmp
#define _wcsicmp wcscasecmp
#define _wcsnicmp wcsncasecmp
#endif

#endif
#endif
